﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace AudioPlayer.GUI.Main {
	internal class MainMenuStrip : MenuStrip {
		#region Variables
		private Point _lastMouseDown;
		#endregion
		#region Private Voids
		private void MoveForm() {
			Form f = this.FindForm();
			if (f != null && _lastMouseDown != null && _lastMouseDown != Point.Empty) {
				//Ok, good to go.
				Point pToScreen = this.PointToScreen(_lastMouseDown);

				int x = MousePosition.X - pToScreen.X;
				int y = MousePosition.Y - pToScreen.Y;
				Point nLocation = new Point(f.Location.X+x,f.Location.Y+ y);
				f.Location = nLocation;
			}
		}
		#endregion
		#region Override
		protected override void OnMouseDown(MouseEventArgs mea) {
			ToolStripItem item = this.GetItemAt(mea.Location);
			if (item == null) {
				_lastMouseDown = mea.Location;
				this.Capture = true;
			} else {
				_lastMouseDown = Point.Empty;
				base.OnMouseDown(mea);
			}
		}
		protected override void OnMouseUp(MouseEventArgs mea) {
			_lastMouseDown = Point.Empty;
			this.Capture = false;
			base.OnMouseUp(mea);
		}
		protected override void OnMouseMove(MouseEventArgs mea) {
			MoveForm();
			base.OnMouseMove(mea);
		}
		#endregion
	}
}
